package com.chuck.blogpro.controller;

import com.chuck.blogpro.pojo.Result;
import com.chuck.blogpro.pojo.Tag;
import com.chuck.blogpro.service.TagService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 标签管理
 * 1. 获取标签列表
 * 2. 添加标签
 * 3. 删除标签
 * 4. 修改标签
 * 5. 查询标签
 */
@RestController
@RequestMapping("/tags")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping
    Result getTags() {
        List<Tag> list = tagService.list();
        return Result.success(list);
    }

    @GetMapping("/{id}")
    Result getTag(@PathVariable Integer id) {
        Tag tag = tagService.getTag(id);
        return Result.success(tag);
    }

    @DeleteMapping("/{id}")
    Result delete(@PathVariable Integer id) {
        tagService.delete(id);
        return Result.success();
    }

    @PostMapping
    Result add(Tag tag) {
        tagService.add(tag);
        return Result.success(tag);
    }

    @PutMapping
    Result update(Tag tag) {
        tagService.update(tag);
        return Result.success(tag);
    }

}
